const { query } = require('express');
var express = require('express');
var router = express.Router();

const { getAllOrders, delOrdersById ,getOneOrderById,getSurrenderOrders,
    handelSurrenderOrders,refuseSurrenderOrders,getSaleManOrder,updateOrderBySaleMan,addOrder} = require('../service/ordersService')

//查看所有订单
router.get('/getAllOrders', async (req, res, next) => {
    res.send(await getAllOrders(req.query))
});

//获取退保订单
router.get('/getSurrenderOrders', async (req, res, next) => {
    res.send(await getSurrenderOrders())
});

//处理退保订单
//同意退保
router.post('/handelSurrenderOrders', async (req, res, next) => {
    res.send(await handelSurrenderOrders(req.body))
});
//拒绝退保
router.post('/refuseSurrenderOrders', async (req, res, next) => {
    res.send(await refuseSurrenderOrders(req.body))
});

//删除订单
router.post('/delOrdersById', async (req, res, next) => {
    res.send(await delOrdersById(req.body))
});

router.post('/getOneOrderById', async (req, res, next) => {
    res.send(await getOneOrderById(req.body))
});

//销售员获取订单列表
router.post('/getSaleManOrder', async (req, res, next) => {
    res.send(await getSaleManOrder(req.body))
});

//销售员修改订单状态
router.post('/updateOrderBySaleMan', async (req, res, next) => {
    res.send(await updateOrderBySaleMan(req.body))
});

//客户下单
router.post('/addOrder', async (req, res, next) => {
    res.send(await addOrder(req.body))
});

module.exports = router;